#ifndef GUITAB_H
#define GUITAB_H

#include <opencv-2.3.1/opencv2/highgui/highgui.hpp>
#include <opencv-2.3.1/opencv2/imgproc/imgproc.hpp>
#include <string>
#include <vector>
using namespace std;

#include "rec.h"

class Gui;

class GuiTab
{
public:
	GuiTab(cv::Rect tabrect, string text, Gui* parent);

	// Returns true if selected as active
	virtual bool HandleInput(int event, cv::Point2d mouse, bool active);
	virtual void Draw(cv::Mat target, bool active);

	void SetSelectable(bool selectable) { mSelectable = selectable; }
protected:
	cv::Rect mTabRect;
	string mText;
	bool mSelectable;
	Gui* mParent;
		int mChosen;
};

class ListRecordingsTab : public GuiTab
{
public:
	ListRecordingsTab(cv::Rect tabrect, Gui* parent);

	static void Init();
	virtual bool HandleInput(int event, cv::Point2d mouse, bool active);
	virtual void Draw(cv::Mat target, bool active);

private:
	static cv::Mat imgRemoveButton;

	const cv::Rect removeButton; // Only clip rect, not pos
	cv::Rect RemoveButtonPos(int nr, int offSet);
	const cv::Rect activateArea; // Only clip rect, not pos
	cv::Rect ActivateAreaPos(int nr, int offSet);
	const cv::Rect transferButton; // Only clip rect, not pos
	cv::Rect TransferButtonPos(int nr, int offSet);
};

class ViewPointsTab : public GuiTab
{
public:
	ViewPointsTab(cv::Rect tabrect, Gui* parent);

	static void Init();
	virtual bool HandleInput(int event, cv::Point2d mouse, bool active);
	virtual void Draw(cv::Mat target, bool active);

private:

        static cv::Mat imgNextButton;
        static cv::Mat imgPrevButton;
        static cv::Mat imgGripButton;

        const cv::Rect nextButton;
        const cv::Rect prevButton;
        const cv::Rect gripButton;

        const cv::Rect next2Button;
        const cv::Rect prev2Button;
};

class Gui
{
public:
	Gui(RecordController *recorder);

	static void Init();

	bool HandleInput(int event, cv::Point2d mouse);
	void Draw(cv::Mat target);

	RecordController* mRec;
	Recording* mActiveRecording;

	// Tabs
	vector<GuiTab*> mTabs;
	unsigned int mActiveTab;
private:
	// Images for buttons
	static cv::Mat imgPlayButton;
	static cv::Mat imgStopButton;
	static cv::Mat imgRecordButton;

	// Hitboxes for buttons
	const cv::Rect playButton;
	const cv::Rect stopButton;
	const cv::Rect recordButton;

	const cv::Rect saveButton;
	const cv::Rect loadButton;
};

#endif // GUITAB_H
